package com.bw.logging;

import com.alibaba.fastjson.JSON;
import com.bw.entity.Role;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;

/**
 * Created by qpx on 2018/5/23.
 */
@Aspect
public class Logging1 {


    @Pointcut("execution(* com.bw.service.impl.RoleServiceImpl.update*(..))")
    public void pointcut(){

    }


    @After(value = "pointcut()")
    public void after(JoinPoint joinPoint) throws Exception {
        System.out.println("注解日志开始....");
        Role role = getMessage(joinPoint.getArgs());
        System.out.println(JSON.toJSONString(role));
    }

    /**
     * 使用Java反射来获取被拦截方法(insert、update)的参数值，
     * 将参数值拼接为操作内容
     */
    public Role getMessage(Object[] args) throws Exception{
        // 遍历参数对象
        for (Object info : args) {
            if(info instanceof  Role){
                Role order = (Role)info;
                return order;
            }
        }
        return null;
    }
}
